package com.lzx.multi;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpGet;

public class URLUtils {
	
	public static  String getFilename(HttpGet httpGet, HttpEntity entity) {
		if(httpGet == null) {
			return null;
		}
		
		String uri = httpGet.getURI().toString();
		
		if(uri.endsWith("/")) {
			String type = entity.getContentType().toString();
			int start = type.indexOf("/");
			if(type.contains(";")) {
				return System.currentTimeMillis()+  "." + type.substring(start+1, type.indexOf(";"));
			} else {
				return "a." + type.substring(start+1, type.length());
			}
			
		}
		String filename = uri.substring(uri.lastIndexOf('/') + 1,
				uri.length());
		return filename;
	}
	
	
	
	
	public static  String getFilename(String url) {
		
		String filename = url.substring(url.lastIndexOf('/') + 1,
				url.length());
		return filename;
	}

}
